package view;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;

import model.kwalificatiebeheer.Competentie;
import model.kwalificatiebeheer.Criterium;

import java.awt.GridBagLayout;
import javax.swing.JLabel;

import controller.AddCompetentieToWerkprocesActions;
import controller.ViewCriteriumActions;

import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.util.ArrayList;

public class ViewCriteriumPanel extends JPanel{
	
	private Criterium c;
	private JTable tblCompetenties;
	private JTable tblComponents;
	private ArrayList<String> components;
	private JTextArea txtPrestatieIndicator;
	private String activeComponent;
	
	public ViewCriteriumPanel(Criterium c){
		this.c = c;
		components = c.getComponenten();
		initGui();
	}
	
	private void initGui(){
		setVisible(true);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 1.0, 1.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JLabel lblPrestatieIndicator = new JLabel("Prestatie Indicator:");
		GridBagConstraints gbc_lblPrestatieIndicator = new GridBagConstraints();
		gbc_lblPrestatieIndicator.anchor = GridBagConstraints.WEST;
		gbc_lblPrestatieIndicator.insets = new Insets(0, 0, 5, 5);
		gbc_lblPrestatieIndicator.gridx = 1;
		gbc_lblPrestatieIndicator.gridy = 1;
		add(lblPrestatieIndicator, gbc_lblPrestatieIndicator);
		
		txtPrestatieIndicator = new JTextArea();
		txtPrestatieIndicator.setText(c.getPrestatieIndicator());
		GridBagConstraints gbc_txtPrestatieIndicator = new GridBagConstraints();
		gbc_txtPrestatieIndicator.gridwidth = 2;
		gbc_txtPrestatieIndicator.insets = new Insets(0, 0, 5, 5);
		gbc_txtPrestatieIndicator.fill = GridBagConstraints.BOTH;
		gbc_txtPrestatieIndicator.gridx = 1;
		gbc_txtPrestatieIndicator.gridy = 2;
		add(txtPrestatieIndicator, gbc_txtPrestatieIndicator);
		
		JLabel lblComponenten = new JLabel("Componenten:");
		GridBagConstraints gbc_lblComponenten = new GridBagConstraints();
		gbc_lblComponenten.anchor = GridBagConstraints.WEST;
		gbc_lblComponenten.insets = new Insets(0, 0, 5, 5);
		gbc_lblComponenten.gridx = 1;
		gbc_lblComponenten.gridy = 3;
		add(lblComponenten, gbc_lblComponenten);
		
		tblComponents = new JTable(new ComponentenTableModel(components));
		tblComponents.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		tblComponents.addMouseListener(new ViewCriteriumActions(this));
		GridBagConstraints gbc_tblComponents = new GridBagConstraints();
		gbc_tblComponents.gridwidth = 2;
		gbc_tblComponents.insets = new Insets(0, 0, 5, 5);
		gbc_tblComponents.fill = GridBagConstraints.BOTH;
		gbc_tblComponents.gridx = 1;
		gbc_tblComponents.gridy = 4;
		add(tblComponents, gbc_tblComponents);
		
		JButton btnComponentVerwijderen = new JButton("Component Verwijderen");
		btnComponentVerwijderen.addActionListener(new ViewCriteriumActions(this));
		btnComponentVerwijderen.setActionCommand("deleteComp");
		GridBagConstraints gbc_btnComponentVerwijderen = new GridBagConstraints();
		gbc_btnComponentVerwijderen.anchor = GridBagConstraints.WEST;
		gbc_btnComponentVerwijderen.insets = new Insets(0, 0, 5, 5);
		gbc_btnComponentVerwijderen.gridx = 1;
		gbc_btnComponentVerwijderen.gridy = 5;
		add(btnComponentVerwijderen, gbc_btnComponentVerwijderen);
		
		JButton btnComponentToevoegen = new JButton("Component Toevoegen");
		btnComponentToevoegen.addActionListener(new ViewCriteriumActions(this));
		btnComponentToevoegen.setActionCommand("addComp");
		GridBagConstraints gbc_btnComponentToevoegen = new GridBagConstraints();
		gbc_btnComponentToevoegen.anchor = GridBagConstraints.EAST;
		gbc_btnComponentToevoegen.insets = new Insets(0, 0, 5, 5);
		gbc_btnComponentToevoegen.gridx = 2;
		gbc_btnComponentToevoegen.gridy = 5;
		add(btnComponentToevoegen, gbc_btnComponentToevoegen);
		
		JButton btnOpslaan = new JButton("Opslaan");
		btnOpslaan.addActionListener(new  ViewCriteriumActions(this));
		btnOpslaan.setActionCommand("btnSave");
		GridBagConstraints gbc_btnOpslaan = new GridBagConstraints();
		gbc_btnOpslaan.anchor = GridBagConstraints.EAST;
		gbc_btnOpslaan.insets = new Insets(0, 0, 5, 5);
		gbc_btnOpslaan.gridx = 2;
		gbc_btnOpslaan.gridy = 6;
		add(btnOpslaan, gbc_btnOpslaan);
	}
	
	public Criterium getCriterium(){
		return c;
	}
	public String getActiveComponent() {
		return activeComponent;
	}

	public void setActiveComponent(String activeComponent) {
		this.activeComponent = activeComponent;
	}

	public JTable getTblCompetenties() {
		return tblCompetenties;
	}

	public JTable getTblComponents() {
		return tblComponents;
	}

	public ArrayList<String> getComponentsCriterium() {
		return components;
	}

	public JTextArea getTxtPrestatieIndicator() {
		return txtPrestatieIndicator;
	}

}
